# encoding: utf-8
#@author: sydr
#@file: CPA_planner.py
#@time: 2025/3/27 16:12

# encoding: utf-8
#@author: sydr
#@file: CPA_evaluation.py
#@time: 2025/3/27 15:04
import json
import random

import math
import mitmproxy

from mitmproxy.http import Request, Response
from mitmproxy import ctx


class CPAPlanner:
    def request(self, flow: mitmproxy.http.HTTPFlow):
        r:Request = flow.request
        # if "userStudyRecord/front/offlineIncrReport" in r.pretty_url:
        #     data = json.loads(r.get_text())
        #
        #     for section in  data["reportQOS"]:
        #         section["studyTime"]=0
        #     r.text = json.dumps(data)



    def response(self, flow: mitmproxy.http.HTTPFlow):
        res: Response = flow.response
        r: Request = flow.request
        # if "/api/v2/abtest/online/results" in r.pretty_url:
        #     data = json.loads(res.get_text())
        #     results=data["results"]
        #     if len(results)==0:
        #         results.append({"variables":[]})
        #
        #         results[0]["variables"].append({
        #             "name":"R_Page",
        #             "value":"PageB"
        #         })

            #
            # for r in results:
            #    if  r["variables"][0]["name"]=="R_Page":
            #        r["variables"][0]["value"]="PageB"
            #        # r["variables"][0]["value"]="PageA"
            # res.text = json.dumps(data)


        #
        # if "commonapi/learnningPlanner/front/resultPageInfo" in r.pretty_url:
        #     data = json.loads(res.get_text())
        #     data["userArchivesDTO"]["passAccountingCertificates"]=""
        #     res.text = json.dumps(data)
        # if "courseapi/taskLibrary/front/getBundleDetailByBundleId" in r.pretty_url:
        #      data = json.loads(res.get_text())
        #      data["data"]["days"][0]["courseInfo"][0]["chapterData"][0]["sectionData"][3]["studyPercent"]=50
        #      data["data"]["days"][0]["courseInfo"][0]["chapterData"][0]["sectionData"][3]["isFinished"]=1
        #      res.text = json.dumps(data)

        # if "/courseapi/dailyTaskPlan/front/selectUserDailyPlan" in r.pretty_url:
        #      data = json.loads(res.get_text())
             # for dayData in data["data"]["dayData"]:
             #     for day in dayData["task"][0]["sectionData"]:
             #         day["isFinished"]=1
             #         day["studyPercent"]=50
             # data["data"].pop("isFinished")
             # res.text = json.dumps(data)

        #   if "/courseapi/dailyTaskPlan/front/selectUserDailyPlan" in r.pretty_url:
        #      data = json.loads(res.get_text())
        #      res.text = json.dumps(data)


        # if "/courseapi/dailyTaskPlan/front/previewDailyPlanNew" in r.pretty_url:
        #     data = json.loads(res.get_text())
        #     for day in data["data"]["dayData"][1]["task"][0]["sectionData"]:
        #         data["data"]["dayData"][0]["task"][0]["sectionData"].append(day)
        #
        #     for day in data["data"]["dayData"][2]["task"][0]["sectionData"]:
        #         data["data"]["dayData"][0]["task"][0]["sectionData"].append(day)
        #     res.text = json.dumps(data)
        # if "commonapi/learnningPlannerUserRecord/front/detail" in r.pretty_url:
        #     data = json.loads(res.get_text())
        #     data["data"]["hasTrigger"]=False
        #     data["data"]["hasFinishQuestion"]=False
        #     data["data"]["place"]=6
        #
        #     res.text = json.dumps(data)
        # if "commonapi/learnningPlanner/getPlaceConfig/front" in r.pretty_url:
        #     data = json.loads(res.get_text())
        #     data["data"]=6
        #     res.text = json.dumps(data)

addons = [
CPAPlanner(),
]

